package com.se.service;

import cn.hutool.core.codec.Base64;
import cn.hutool.extra.qrcode.QrCodeUtil;
import cn.hutool.extra.qrcode.QrConfig;
import org.springframework.stereotype.Service;

import java.io.ByteArrayOutputStream;


@Service
public class QrCodeService {
    QrConfig config = new QrConfig(200, 200);

    public String base64(String url){
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        QrConfig config = new QrConfig(300, 300);
        QrCodeUtil.generate(url, config, "jpg", outputStream);

        // 将生成的二维码数据转换为Base64编码字符串返回
        return "data:image/jpeg;base64," + Base64.encode(outputStream.toByteArray());
    }
}
